/*
 * User: rant
 * Date: Aug 6, 2007
 *
 *
 */
package laMalinche.propertyChangeAdapters.model;

import laMalinche.rete.nodes.tailing.AccessReporter;
import laMalinche.rete.nodes.tailing.PropertyTouchedListener;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
import java.util.Set;

/**
 *
 */
public class AccessReporterImp  implements AccessReporter , PropertyChangeListener {
	private final Set<PropertyTouchedListener> listeners = new HashSet<PropertyTouchedListener>();

    private static final Logger log = LogManager.getLogger(AccessReporterImp.class);

	public void addAccessListener(final PropertyTouchedListener basicTailingManager) {
        listeners.add(basicTailingManager);
	}

	public void removeAccessListener(final PropertyTouchedListener basicTailingManager) {
		if (!listeners.contains(basicTailingManager)){
			log.error("something went wrong");
		}
	listeners.remove(basicTailingManager);
	}

	public void propertyChange(PropertyChangeEvent evt) {
		fireEvent(evt);
	}

	void fireEvent(PropertyChangeEvent event){
		for (PropertyTouchedListener listener:listeners){
			final VOEntityImp vo = new VOEntityImp(event);
			listener.propertyTouched(vo);
		}
	}
}